﻿using MyMES.Error;
using MyMES.Infrastructure;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Infrastructure.Interface;
using AutoMapper;
using MyMES.Writer.API.Application.Commends.pressions;

namespace MyMES.Writer.API.Application.CommendHandlers.Pressions
{
    public class AddPressionHandler : IRequestHandler<AddPressionCommand, APIResult<Pression>>
    {
        private readonly IBaseRepository<Pression> pre;
        private readonly IMapper mapper;

        public AddPressionHandler(IBaseRepository<Pression> pre, IMapper mapper)
        {
            this.pre = pre;
            this.mapper = mapper;
        }

        public async Task<APIResult<Pression>> Handle(AddPressionCommand request, CancellationToken cancellationToken)
        {
            APIResult<Pression> result = new APIResult<Pression>();
            result.Code = APIEnum.添加成功;
            result.Msg = "添加成功";
            var model = mapper.Map<Pression>(request);
            string sql = "insert into Pression(PressId,PressName,IsDlete) values(@PressId,@PressName,@IsDlete)";
            await pre.Insert(model, sql);
            return result;
        }
    }
}
